﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NetfractionHub.LocalMachine.BotCommands;
using NetfractionHub.Network.Protocol;
using NetfractionHub.Network.Protocol.BASE.Factory;
using NetfractionHub.Network.Protocol.UCMD;
using NetfractionHub.Network.Protocol.UCMD.Factory;

namespace AnnouncerBot.Handlers
{
    [CommandHandler("addcategory")]
    [UserCommand("Add Category", FactoryCMD.ConextTypesEnum.HubCommand, "HMSG {0}addcategory\\\\s%[line:Category name]\n")]
    public class AddCategory : CommandHandler
    {
        public override BotReturnStatus HandleCommandMessage(NetfractionHub.RemoteMachine.Node source, CommandMessage message)
        {
            if (message.ArgumentsCount == 1)
            {
                string catName = string.Empty;
                if (message.StringArguments.Count == 1 && message.StringArguments.ContainsKey("name"))
                    catName = message.StringArguments["name"];
                else if (message.UnnamedArguments.Count == 1)
                    catName = message.UnnamedArguments[0];

                int retVal = AnnouncerBot.DataStore.ExecuteNonQuery(String.Format(System.Globalization.CultureInfo.InvariantCulture, "INSERT INTO Categories (Name) VALUES ('{0}')", catName));
                if (retVal == 1)
                    return new BotReturnStatus(true, string.Format(System.Globalization.CultureInfo.InvariantCulture, "The category '{0}' has been added to the Announcer database.", catName));
            }
            return false;
        }
    }
}
